package arkanoid.utils;

import java.util.ArrayList;
import java.util.List;

import arkanoid.components.Brick;

public class WallMaker {
	
	private int   difference;
	private int   posX;
	private int   posY;

	public WallMaker(int difference, int x, int y) {
		this.setDifference(difference);
		this.setPosX(x);
		this.setPosY(y);
	}
	
	public List<Brick> construct(int amount, int wMax) {
		List<Brick> bricks = new ArrayList<Brick>();
		for (int i = 0; i < amount; i++) {
			int next = 1 + (int)(Math.random() * ((3 - 1) + 1));
			Brick brick = new Brick(this.getPosX(), this.getPosY(), next);
			bricks.add(brick);
			
			if(this.getPosX() + brick.getWidth() * 2 + this.getDifference() > wMax) {
				this.setPosY(this.getPosY() + brick.getHeight() + this.getDifference());
				this.setPosX(this.getDifference());
			}
			else {
				this.setPosX(this.getPosX() + brick.getWidth() + this.getDifference());
			}
		}
		return bricks;
	}
	

	public int getPosX() {
		return posX;
	}

	public void setPosX(int posX) {
		this.posX = posX;
	}

	public int getPosY() {
		return posY;
	}

	public void setPosY(int posY) {
		this.posY = posY;
	}

	public int getDifference() {
		return difference;
	}

	public void setDifference(int difference) {
		this.difference = difference;
	}
}
